package com.zy;

/**
 * @program: shopping153_cloud
 * @description:
 * @author: zy
 * @create: 2025-08-23 11:04
 */

import com.zy.bean.Contributor;
import com.zy.restApi.GitHub2_javax;
import feign.gson.GsonDecoder;
import feign.hystrix.HystrixFeign;
import feign.jaxrs.JAXRSContract;
import feign.okhttp.OkHttpClient;

import java.util.Collections;
import java.util.List;

public class App3_hystrix_javax {
    public static void main(String[] args) {

        // 设置 Hystrix 全局超时时间（5秒） ,   默认是1秒， 所以会超时.
//        System.setProperty(
//                "hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds",
//                "5000"
//        );

        GitHub2_javax github = HystrixFeign.builder()
                .decoder(new GsonDecoder())
                .client(new OkHttpClient())
                .contract(new JAXRSContract())

                .target(GitHub2_javax.class, "https://api.github.com",
                        (owner, repo) -> Collections.emptyList()   // fallback：超时时返回空列表
                );


        List<Contributor> contributors = github.contributors("OpenFeign", "feign");
        for (Contributor contributor : contributors) {
            System.out.println(contributor);
        }
    }
}
